<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  <meta name="renderer" content="webkit">
  <title></title>
  <link rel="stylesheet" href="/static/css/pintuer.css">
  <link rel="stylesheet" href="/static/css/admin.css">
  <script src="/static/js/jquery.js"></script>
  <script src="/static/js/pintuer.js"></script>
</head>
<body>
<form method="post" action="" id="listform">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 管理员列表</strong>
      <a href="" style="float:right; display:none;">添加字段</a>
    </div>
    <table id="class_list" class="table table-hover text-center">
      <thead>
        <tr class="t_head">
          <th width="100" style="text-align:left; padding-left:20px;">ID</th>
          <th width="10%">用户名</th>
          <th>密码</th>
          <th>真实姓名</th>
        </tr>
      </thead>
      <tbody class="t-body">

      </tbody>


    </table>
  </div>
</form>
<script type="text/javascript">
  $(function () {

    loadListClazz()
  })

  function loadListClazz() {
    $.ajax({
      url: "/user/list",
      type: "GET",
      dataType: "JSON",
      success: function (res) {
        console.log(res);
        let str = '';
        for (let i = 0; i < res.data.length; i++) {
          str += `<tr>
                <td style="text-align:left; padding-left:20px;">${res.data[i].id}</td>
                <td>${res.data[i].username}</td>
                <td>${res.data[i].password}</td>
                <td>${res.data[i].realname}</td>
                <td>
                    <div class="button-group">
                            <a class="button border-red" href="javascript:void(0)" onclick="return del(${res.data[i].id})">
                            <spanclass="icon-trash-o"></span> 删除</a>
                     </div>
                </td>
            </tr>`;
        }
        $(".t-body").html(str);

      }
    })
  }



  //单个删除
  function del(id) {
    if (confirm("您确定要删除吗?")) {
      $.ajax({
        url: "/user/delete",
        data: {
          id: id
        },
        type: "POST",
        dataType: "JSON",
        success: function (res) {
          if (res.code === 200) {
            alert("删除成功");
            location.reload()
          }
        }
      })
    }
  }

</script>
</body>
</html>